//
//  AXFspecialViewController.m
//  AIXF
//
//  Created by mac on 2017/7/14.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "AXFspecialViewController.h"
#import "AXFregulationsTableViewCell.h"
#import "AXFMyCouponModel.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "AXFWebServeManager.h"
#import "AXFHomeViewModel.h"
#import "AXFMyCouponViewModel.h"
#import "AXFHeaderController.h"
@interface AXFspecialViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSArray *dataArray;
@property(nonatomic,strong)NSArray <AXFMyCouponModel*> *couponModel;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UIView *headerView;
@end
static NSString *regulations = @"regulations";
@implementation AXFspecialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
  
    [self fieldView];
    [self setupUI];
    [self setNav];
    [self receiceArray];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiceArray) name:@"postData" object:nil];
    
   
   
}

-(void)fieldView{
    
    AXFHeaderController *headerView = [[AXFHeaderController alloc]init];
    _headerView = headerView;
     [self.view addSubview:headerView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.offset(80);
    }];

   
    
    
}
 

//导航栏设置
-(void)setNav{
    self.navigationItem.title = @"优惠券";
    UIBarButtonItem *regulations = [[UIBarButtonItem alloc]initWithTitle:@"使用规则" style:UIBarButtonItemStylePlain target:self action:@selector(Chilck)];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationItem.rightBarButtonItem = regulations;
}

-(void)Chilck{
    
    NSLog(@"使用规则界面");
    
}


-(void)receiceArray{
    
    self.dataArray = [AXFMyCouponViewModel sharedInstance].couponViewModel;
    
    [self.tableView reloadData];

}


-(void)setupUI{
    UITableView *tableView = [[UITableView alloc]init];
       [self.view addSubview:tableView];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
        
    }];
    
 
    
    _tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.rowHeight = 125;
    
    [tableView registerNib:[UINib nibWithNibName:@"AXFregulationsTableViewCell" bundle:nil] forCellReuseIdentifier:regulations];
    
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AXFregulationsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"regulations" forIndexPath:indexPath];
    
    //把模型和cell的行数对应起来,来判断行内容
    AXFMyCouponModel *model =self.dataArray[indexPath.row];
    if (indexPath.row == 0) {
        
        model.is_bg = YES;
    }
    //展示
    cell.model = model;
    
    
    
    //展示
//    cell.model = self.dataArray[indexPath.row];
    return  cell;
    
}

@end
